function varargout = gui_project_settings(varargin)
% GUI_PROJECT_SETTINGS MATLAB code for gui_project_settings.fig
%      GUI_PROJECT_SETTINGS, by itself, creates a new GUI_PROJECT_SETTINGS or raises the existing
%      singleton*.
%
%      H = GUI_PROJECT_SETTINGS returns the handle to a new GUI_PROJECT_SETTINGS or the handle to
%      the existing singleton*.
%
%      GUI_PROJECT_SETTINGS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_PROJECT_SETTINGS.M with the given input arguments.
%
%      GUI_PROJECT_SETTINGS('Property','Value',...) creates a new GUI_PROJECT_SETTINGS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_project_settings_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_project_settings_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui_project_settings

% Last Modified by GUIDE v2.5 12-Sep-2012 11:34:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_project_settings_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_project_settings_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before gui_project_settings is made visible.
function gui_project_settings_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to gui_project_settings (see VARARGIN)

% Choose default command line output for gui_project_settings
try
    handles.output = hObject;

    % Update handles structure
    guidata(hObject, handles);

    gui_main = find(strcmp(varargin, 'gui_main'));
    if (isempty(gui_main)) || ...
            (length(varargin) <= gui_main) || ...
            (~ishandle(varargin{gui_main+1}))
        dontOpen = true;
    else
        handles.gui_main = varargin{gui_main+1};
        handlesMain = guidata(handles.gui_main);
        handles.project = handlesMain.project;
        guidata(hObject, handles);

        set(handles.frames_per_batch_rough_text, 'String',...
            num2str(handles.project.frames_per_batch_rough));
        set(handles.read_write_attempts_rough_text, 'String',...
            num2str(handles.project.read_write_attempts_rough));
        set(handles.signals_per_mask_text, 'String',...
            num2str(handles.project.signals_per_mask));
        set(handles.signals_per_mask_text, 'String',...
            num2str(handles.project.signals_per_mask));
        set(handles.smoothing_passes_text, 'String',...
            num2str(handles.project.moving_average_smoothing_passes));
        set(handles.moving_average_span_text, 'String',...
            num2str(handles.project.moving_average_span));
        if(handles.project.do_poly_fit)
            set(handles.polynomial_fit_radio, 'Value', 1);
        else
            set(handles.moving_average_radio, 'Value', 1);
        end
        set(handles.moving_average_span_text, 'String',...
            num2str(handles.project.moving_average_span));
        set(handles.polynomial_fit_degree_1_checkbox, 'Value',...
            handles.project.poly_fit_degree(1));
        set(handles.polynomial_fit_degree_2_checkbox, 'Value',...
            handles.project.poly_fit_degree(2));
        set(handles.polynomial_fit_degree_3_checkbox, 'Value',...
            handles.project.poly_fit_degree(3));
        set(handles.polynomial_fit_degree_4_checkbox, 'Value',...
            handles.project.poly_fit_degree(4));
        set(handles.frames_for_overlap_guess_text, 'String',...
            num2str(handles.project.frames_for_overlap_guess));
        set(handles.initial_search_radius_text, 'String',...
            num2str(handles.project.initial_search_radius));
        set(handles.local_min_neighborhood_radius_text, 'String',...
            num2str(handles.project.local_min_neighborhood_radius));
        set(handles.max_rows_to_ignore_text, 'String',...
            num2str(handles.project.max_rows_to_ignore));
        if(handles.project.max_rows_to_ignore_is_percent)
            set(handles.max_rows_to_ignore_popup, 'Value', 2);
        else
            set(handles.max_rows_to_ignore_popup, 'Value', 1);
        end
        set(handles.overlap_threshold_text, 'String',...
            num2str(handles.project.overlap_threshold));
        set(handles.smooth_sound_checkbox, 'Value', ...
            handles.project.do_smooth_sound);
        set(handles.smooth_sound_moving_average_span_text, 'String',...
            num2str(handles.project.smooth_sound_moving_average_span));


        % UIWAIT makes gui_project_settings wait for user response (see UIRESUME)
        uiwait(hObject);
    end
catch exception
    gui_exception(exception);
end



% --- Outputs from this function are returned to the command line.
function varargout = gui_project_settings_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;
delete(hObject);

% --- Executes on button press in log_file_checkbox.
function log_file_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to log_file_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of log_file_checkbox


% --- Executes on button press in sound_only_checkbox.
function sound_only_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to sound_only_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of sound_only_checkbox



function signals_per_mask_text_Callback(hObject, eventdata, handles)
% hObject    handle to signals_per_mask_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of signals_per_mask_text as text
%        str2double(get(hObject,'String')) returns contents of signals_per_mask_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.signals_per_mask = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function signals_per_mask_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to signals_per_mask_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function frames_for_overlap_guess_text_Callback(hObject, eventdata, handles)
% hObject    handle to frames_for_overlap_guess_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of frames_for_overlap_guess_text as text
%        str2double(get(hObject,'String')) returns contents of frames_for_overlap_guess_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.frames_for_overlap_guess = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function frames_for_overlap_guess_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to frames_for_overlap_guess_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function initial_search_radius_text_Callback(hObject, eventdata, handles)
% hObject    handle to initial_search_radius_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of initial_search_radius_text as text
%        str2double(get(hObject,'String')) returns contents of initial_search_radius_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.initial_search_radius = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function initial_search_radius_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to initial_search_radius_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function local_min_neighborhood_radius_text_Callback(hObject, eventdata, handles)
% hObject    handle to local_min_neighborhood_radius_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of local_min_neighborhood_radius_text as text
%        str2double(get(hObject,'String')) returns contents of local_min_neighborhood_radius_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.local_min_neighborhood_radius = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function local_min_neighborhood_radius_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to local_min_neighborhood_radius_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function max_rows_to_ignore_text_Callback(hObject, eventdata, handles)
% hObject    handle to max_rows_to_ignore_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of max_rows_to_ignore_text as text
%        str2double(get(hObject,'String')) returns contents of max_rows_to_ignore_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 0)
        val = 0;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.max_rows_to_ignore = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function max_rows_to_ignore_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to max_rows_to_ignore_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in max_rows_to_ignore_popup.
function max_rows_to_ignore_popup_Callback(hObject, eventdata, handles)
% hObject    handle to max_rows_to_ignore_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns max_rows_to_ignore_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from max_rows_to_ignore_popup
try
    idx = get(hObject,'Value');
    string_list = get(hObject,'String');
    units = string_list{idx};
    handles.project.max_rows_to_ignore_is_percent = strcmp(units,'%');
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function max_rows_to_ignore_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to max_rows_to_ignore_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function overlap_threshold_text_Callback(hObject, eventdata, handles)
% hObject    handle to overlap_threshold_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of overlap_threshold_text as text
%        str2double(get(hObject,'String')) returns contents of overlap_threshold_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val < 0)
        val = 0;
    end
    set(hObject,'String',num2str(val));
    handles.project.overlap_threshold = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function overlap_threshold_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to overlap_threshold_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function frames_per_batch_rough_text_Callback(hObject, eventdata, handles)
% hObject    handle to frames_per_batch_rough_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of frames_per_batch_rough_text as text
%        str2double(get(hObject,'String')) returns contents of frames_per_batch_rough_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.frames_per_batch_rough = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function frames_per_batch_rough_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to frames_per_batch_rough_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function read_write_attempts_rough_text_Callback(hObject, eventdata, handles)
% hObject    handle to read_write_attempts_rough_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of read_write_attempts_rough_text as text
%        str2double(get(hObject,'String')) returns contents of read_write_attempts_rough_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.read_write_attempts_rough = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function read_write_attempts_rough_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to read_write_attempts_rough_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in moving_average_set_options.
function moving_average_set_options_Callback(hObject, eventdata, handles)
% hObject    handle to moving_average_set_options (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in polynomial_fit_set_options.
function polynomial_fit_set_options_Callback(hObject, eventdata, handles)
% hObject    handle to polynomial_fit_set_options (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in smooth_sound_checkbox.
function smooth_sound_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to smooth_sound_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of smooth_sound_checkbox
try
    handles.project.do_smooth_sound = (get(hObject, 'Value'));
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end

function smooth_sound_moving_average_span_text_Callback(hObject, eventdata, handles)
% hObject    handle to smooth_sound_moving_average_span_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of smooth_sound_moving_average_span_text as text
%        str2double(get(hObject,'String')) returns contents of smooth_sound_moving_average_span_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.smooth_sound_moving_average_span = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end

% --- Executes during object creation, after setting all properties.
function smooth_sound_moving_average_span_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to smooth_sound_moving_average_span_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function smoothing_passes_text_Callback(hObject, eventdata, handles)
% hObject    handle to smoothing_passes_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of smoothing_passes_text as text
%        str2double(get(hObject,'String')) returns contents of smoothing_passes_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.moving_average_smoothing_passes = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function smoothing_passes_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to smoothing_passes_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function moving_average_span_text_Callback(hObject, eventdata, handles)
% hObject    handle to moving_average_span_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of moving_average_span_text as text
%        str2double(get(hObject,'String')) returns contents of moving_average_span_text as a double
try
    val = str2double(get(hObject,'String'));
    if isnan(val) || (val <= 1)
        val = 1;
    else
        val = floor(val);
    end
    set(hObject,'String',num2str(val));
    handles.project.moving_average_span = val;
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function moving_average_span_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to moving_average_span_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in polynomial_fit_degree_1_checkbox.
function polynomial_fit_degree_1_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to polynomial_fit_degree_1_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of polynomial_fit_degree_1_checkbox
try
    handles.project.poly_fit_degree(1) = get(hObject, 'Value');
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end

% --- Executes on button press in polynomial_fit_degree_2_checkbox.
function polynomial_fit_degree_2_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to polynomial_fit_degree_2_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of polynomial_fit_degree_2_checkbox
try
    handles.project.poly_fit_degree(2) = get(hObject, 'Value');
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes on button press in polynomial_fit_degree_3_checkbox.
function polynomial_fit_degree_3_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to polynomial_fit_degree_3_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of polynomial_fit_degree_3_checkbox
try
    handles.project.poly_fit_degree(3) = get(hObject, 'Value');
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes on button press in polynomial_fit_degree_4_checkbox.
function polynomial_fit_degree_4_checkbox_Callback(hObject, eventdata, handles)
% hObject    handle to polynomial_fit_degree_4_checkbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of polynomial_fit_degree_4_checkbox
try
    handles.project.poly_fit_degree(4) = get(hObject, 'Value');
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end


% --- Executes on button press in cancel_button.
function cancel_button_Callback(hObject, eventdata, handles)
% hObject    handle to cancel_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    gui_close_figure(handles.project_settings_figure);
catch exception
    gui_exception(exception);
end


% --- Executes on button press in ok_button.
function ok_button_Callback(hObject, eventdata, handles)
% hObject    handle to ok_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    mainHandles = guidata(handles.gui_main);
    mainHandles.project = handles.project;
    guidata(handles.gui_main, mainHandles);
    gui_close_figure(handles.project_settings_figure);
catch exception
    gui_exception(exception);
end


% --- Executes during object creation, after setting all properties.
function project_settings_figure_CreateFcn(hObject, eventdata, handles)
% hObject    handle to project_settings_figure (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes when user attempts to close project_settings_figure.
function project_settings_figure_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to project_settings_figure (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    gui_close_figure(handles.project_settings_figure);
catch exception
    gui_exception(exception);
end


% --- Executes when selected object is changed in waveform_panel.
function waveform_panel_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in waveform_panel 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
try
    if(eventdata.NewValue == handles.moving_average_radio)
        handles.project.do_poly_fit = false;
    else
        handles.project.do_poly_fit = true;
    end
    guidata(hObject, handles);
catch exception
    gui_exception(exception);
end
